<template>
  <view class="page">
    <!-- <image src="@/static/images/demo/3.jpg" style="width: 100%;" mode="widthFix"></image> -->
    <view class="add-active">
      <view class="group flex flex-c">
        <view class="key">姓名</view>
        <u-input
          placeholder="請輸入"
          placeholderStyle="color:#6e6e79"
          class="u-input flex-1"
          v-model="form.data1"
          :type="type"
          :border="border"
        />
      </view>
     
     
      <view class="group flex flex-c">
        <view class="key">聯系方式</view>
        <u-input
          class="u-input flex-1"
          v-model="form.data7"
          :type="type"
          placeholderStyle="color:#6e6e79"
          placeholder="請輸入"
          :border="border"
        />
      </view>
      <view class="group flex flex-c">
        <view class="key">微訊號</view>
        <u-input
          placeholder="請輸入"
          placeholderStyle="color:#6e6e79"
          class="u-input flex-1"
          v-model="form.data1"
          :type="type"
          :border="border"
        />
      </view>
      <view class="group flex flex-c">
        <view class="key">身份證號</view>
        <u-input
          placeholder="請輸入"
          placeholderStyle="color:#6e6e79"
          class="u-input flex-1"
          v-model="form.data1"
          :type="type"
          :border="border"
        />
      </view>
      <view class="group flex flex-c">
        <view class="key">身份證上傳</view>
        <u-upload
          :fileList="fileList1"
          @afterRead="afterRead"
          @delete="deletePic"
          name="1"
          multiple
          :maxCount="10"
        ></u-upload>
      </view>
      <view class="group">
        <view class="btn">提交</view>
      </view>
    </view>
   
  </view>
</template>

<script>
export default {
  data() {
    return {
      fileList1: [],
      // 演示地址，请勿直接使用
      action: "http://www.example.com/upload",
      fileList: [
        {
          url: "http://pics.sc.chinaz.com/files/pic/pic9/201912/hpic1886.jpg",
        },
      ],
      form: {},
      type: "text",
      height: 36,
      border: "surround",
    };
  },
  onLoad() {},
  onReachBottom() {},
  methods: {
    // 删除图片
    deletePic(event) {
      this[`fileList${event.name}`].splice(event.index, 1);
    },
    // 新增图片
    async afterRead(event) {
      // 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
      let lists = [].concat(event.file);
      let fileListLen = this[`fileList${event.name}`].length;
      lists.map((item) => {
        this[`fileList${event.name}`].push({
          ...item,
          status: "uploading",
          message: "上传中",
        });
      });
      for (let i = 0; i < lists.length; i++) {
        const result = await this.uploadFilePromise(lists[i].url);
        let item = this[`fileList${event.name}`][fileListLen];
        this[`fileList${event.name}`].splice(
          fileListLen,
          1,
          Object.assign(item, {
            status: "success",
            message: "",
            url: result,
          })
        );
        fileListLen++;
      }
    },
    uploadFilePromise(url) {
      return new Promise((resolve, reject) => {
        let a = uni.uploadFile({
          url: "http://192.168.2.21:7001/upload", // 仅为示例，非真实的接口地址
          filePath: url,
          name: "file",
          formData: {
            user: "test",
          },
          success: (res) => {
            setTimeout(() => {
              resolve(res.data.data);
            }, 1000);
          },
        });
      });
    },
    confirm(e) {
      this.show1 = false;
      console.log(e);
      this.form.data2=e.value[0].label
      console.log(this.form.data2);
    },
    change(e) {
      console.log(e);
      this.show = false;
      this.form.data4=e[0]+'~'+e[1]
    },
  },
};
</script>

<style lang="scss">
.page {
  height: 100%;
  padding: 16px;
  background: #fbfbfb;
 
}
.add-active {
  background: #fff;
  box-shadow: 1px 1px 5px #999;
  // margin: 24px;
  padding: 20px;
  border-radius: 10px;
  min-height: 80vh;
  .group {
    margin-top: 16px;
    .btn {
      margin-top: 25px;
      background: #000;
      color: #fff;
      height: 40px;
      line-height: 40px;
      text-align: center;
      border-radius: 10px;
    }
    .tip {
      color: grey;
      font-size: 14px;
      .star {
        margin-right: 5px;
      }
    }
    .u-input {
      padding: 0 10px;
      background: #f0f3f8;
      color: #6e6e79;
      text-indent: 5px;
      border-radius: 8px;
      line-height: 40px;
      font-size: 16px;
      position: relative;
      .icon{
        position: absolute;
        right: 8px;
        top: 12px;
      }
    }
    .key {
      margin-right: 20px;
      width: 80px;
      text-align: right;
    }
  }
}
</style>
